package cn.vcjf.washcar.server.controller;


import cn.vcjf.washcar.common.web.TableResult;
import cn.vcjf.washcar.server.entity.MerchQrcode;
import cn.vcjf.washcar.server.service.MerchQrcodeService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-07-18
 */
@Controller
@RequestMapping("/server/merchQrcode")
public class MerchQrcodeController {
     @Resource
     private MerchQrcodeService  merchQrcodeService;

     @RequestMapping("/addMerchQrcode")
     @ResponseBody
     public TableResult addMerchQrcode(MerchQrcode merchQrcode){
         merchQrcode.preInsert();
         merchQrcode.setStatus(0);
         boolean b = merchQrcodeService.insert(merchQrcode);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateMerchQrcode")
     @ResponseBody
     public TableResult updateMerchQrcode(MerchQrcode merchQrcode){
         merchQrcode.preUpdate();
        boolean b = merchQrcodeService.updateById(merchQrcode);
         return TableResult.Result(b);
     }

     @RequestMapping("/findMerchQrcodeOne")
     @ResponseBody
     public TableResult findMerchQrcodeOne(MerchQrcode merchQrcode){

        EntityWrapper<MerchQrcode> wrapper = merchQrcode.getQueryWrapper();

        MerchQrcode result = merchQrcodeService.selectOne(wrapper);

		return TableResult.Result(result);
     }

     @RequestMapping("/findMerchQrcodeList")
     @ResponseBody
     public TableResult findMerchQrcodeList(MerchQrcode merchQrcode){

        EntityWrapper<MerchQrcode> wrapper = merchQrcode.getQueryWrapper();

        Page<MerchQrcode> page = merchQrcode.getPageInfo();

		page = merchQrcodeService.selectPage(page,wrapper);

		return TableResult.Result(page);

     }

    @RequestMapping("/deleteMerchQrcodeByIds")
    @ResponseBody
    public TableResult deleteMerchQrcodeByIds(String... ids) {
        List<String> list = Arrays.asList(ids);
        boolean b = merchQrcodeService.deleteBatchIds(list);
        return TableResult.Result(b);
    }
}
